Fix chat prompt message deserialization when type is missing#17
Closed
Seayon wants to merge 1 commit intolangfuse:mainfrom
Closed
Fix chat prompt message deserialization when type is missing#17Seayon wants to merge 1 commit intolangfuse:mainfrom
Seayon wants to merge 1 commit intolangfuse:mainfrom
Conversation
8dc9f53 to
46741fe
Compare
Member
|
@Seayon These clients are auto-generated, i.e. on the next update this patch would be overwritten. Addressing the discrepancy within the spec (https://github.com/langfuse/langfuse/blob/main/fern/apis/server/definition/prompts.yml#L164) would be the correct approach. Could you add two more thoughts on what the intended behavior would be? Alternatively, feel free to suggest an update to the fern spec. |
Member
|
I'll go ahead and close this, as a direct patch to the Java client here is not applicable in this scenario. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
typefield (chatmessage/placeholder) in API responses.role/content→ chatmessage,name→ placeholder).typevalues and unknown payloads.Context
Langfuse API returns chat prompt messages with
{role, content}but without thetypefield.The SDK expects
typeforChatMessageWithPlaceholdersand falls back to_UnknownValue, which makesisChatmessage()false and causes chat prompt content to be lost.Using
JsonTypeInfo.Id.DEDUCTIONdoes not work becausechatmessageandplaceholderare structurally ambiguous for Jackson deduction.Changes
ChatMessageWithPlaceholdersnow uses a custom Jackson deserializer:typeis present, parse bytype.role/contentexists, parse asChatMessage.nameexists, parse asPlaceholderMessage._UnknownValuewith raw payload.Files
src/main/java/com/langfuse/client/resources/prompts/types/ChatMessageWithPlaceholders.javaTest Plan
mvn -DskipTests install.getChat().getPrompt()contains system/user messages.Curl Example
Example (sanitized)
{ "id": "069af3bc-xxx", "createdAt": "2026-01-08T05:53:05.355Z", "updatedAt": "2026-01-08T05:53:11.482Z", "projectId": "xxx", "createdBy": "xxxx", "prompt": [ { "role": "system", "content": "- Role:..." }, { "role": "user", "content": "my name is {name}..." } ], "name": "my-classify-prompt", "version": 4, "type": "chat", "isActive": true, "config": {}, "tags": [], "labels": [ "production", "latest", "dev", "test" ], "commitMessage": "first ", "resolutionGraph": null }